< previous page page_593 next page >

Page 593
Visual Basic provides three methods for transaction processing. These methods perform the following functions:
Transaction Method
Function
BeginTrans
Starts a transaction and sets the initial state of the database.
RollBack
Returns the database to its initial state before the BeginTrans statement was issued. When RollBack is executed, all changes made after the last BeginTrans statement are discarded.
CommitTrans
Permanently saves all changes to the database made since the last BeginTrans statement. After the CommitTrans statement is issued, the transactions cannot be undone.

Listing 26.3 shows the BeginTrans, RollBack, and CommitTrans methods as they are used in an order entry application. The transactions are used in case a customer cancels an order prior to the completion of the order processing.
Listing 26.3 TRANSACT.TXTUsing Transaction Processing to Handle Multiple Changes to a Database As One Group
OldWs.BeginTrans
'**********************************************
'Perform loop until user ends sales transaction
'**********************************************
Do While Sales
'**********************************************
'Get item number and sales quantity from form
' Input Itemno,SalesQty
' Find item number in inventory
'**********************************************
   Inv.FindFirst "ItemNum = " & Itemno
'*************************
'Update inventory quantity
'*************************
   Inv.Edit
   Inv("Quantity") = Inv("Quantity") - SalesQty
   Inv.Update
Loop
'*****************************************
'User either completes or cancels the sale
'*****************************************
If SaleComp Then
   OldWs.CommitTrans
Else
   OldWs.Rollback
End If

 
< previous page page_593 next page >